﻿package frEngine.loaders.particleSub
{
    import flash.geom.*;
    import frEngine.loaders.particleSub.particleInstance.*;
    import frEngine.math.*;

    public class RoundEmitter extends EmitterObject
    {
        private var _R:Number = 0;
        private var _instance3dArr:Array;
        private var _segment:int = 30;
        private var _isRandom:Boolean = true;
        private var _radian:Number = 0;
        private var _rotateY:Number = 0;
        private var _rotateX:Number = 0;
        private var _rotateZ:Number = 0;
        private var _roteteOffset:Number = 0;
        private var _qu:Quaternion;
        private var ve:Vector3D;

        public function RoundEmitter(param1:Number, param2:Number, param3:Number, param4:Number, param5:Number, param6:String, param7:Boolean, param8:String)
        {
            this.ve = new Vector3D();
            this._R = param1;
            this._isRandom = param7;
            this._radian = param2 > 360 ? (param2 % 360) : (param2);
            this._radian = this._radian / 180 * Math.PI;
            this._roteteOffset = (-this._radian) / 2;
            this._rotateX = param3 / 180 * Math.PI;
            this._rotateY = param4 / 180 * Math.PI;
            this._rotateZ = param5 / 180 * Math.PI;
            if (this._rotateX != 0 || this._rotateY != 0 || this._rotateZ != 0)
            {
                this._qu = this.createQuaternion();
            }
            super(param6, param8);
            return;
        }// end function

        override public function get meshData() : MeshBase
        {
            if (!_meshData && !hasDisposed)
            {
                _meshData = new RoundData(this._R, 10, this._radian, this._qu);
            }
            return _meshData;
        }// end function

        override protected function processVolume(param1:int) : void
        {
            this.processCurve(param1);
            var _loc_2:* = randnomArr1[param1];
            _vect3d.x = _vect3d.x * _loc_2;
            _vect3d.z = _vect3d.z * _loc_2;
            _vect3d.y = _vect3d.y * _loc_2;
            return;
        }// end function

        override protected function processAxis(param1:int) : void
        {
            _vect3d.y = 0;
            _vect3d.x = 0;
            _vect3d.z = 0;
            return;
        }// end function

        override protected function processCurve(param1:int) : void
        {
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            if (this._isRandom)
            {
                _loc_3 = randnomArr0[param1];
                _loc_2 = this._radian * _loc_3 + this._roteteOffset;
            }
            else
            {
                _loc_2 = this._radian * param1 / particleNum + this._roteteOffset;
            }
            _vect3d.z = this._R * Math.cos(_loc_2);
            _vect3d.x = this._R * Math.sin(_loc_2);
            _vect3d.y = 0;
            return;
        }// end function

        override protected function processEdage(param1:int) : void
        {
            this.processCurve(param1);
            return;
        }// end function

        override protected function processVertex(param1:int) : void
        {
            this.processCurve(param1);
            return;
        }// end function

        override public function getObject3d()
        {
            if (emitterPosType == EmitterPosType.TextureRGB)
            {
                return this.meshData;
            }
            if (!this._instance3dArr)
            {
                this._instance3dArr = new Array();
                this.createLineData0(this._instance3dArr);
            }
            return this._instance3dArr;
        }// end function

        private function createLineData0(param1:Array) : void
        {
            var _loc_2:* = new Array();
            var _loc_3:* = this._radian / this._segment;
            var _loc_4:Number = 0;
            var _loc_5:int = 0;
            while (_loc_5 <= this._segment)
            {
                
                if (this._radian != 2 * Math.PI && _loc_5 == 0)
                {
                    _loc_2.push(0, 0, 0);
                }
                _loc_4 = _loc_3 * _loc_5 + this._roteteOffset;
                this.ve.z = Math.cos(_loc_4) * this._R;
                this.ve.x = Math.sin(_loc_4) * this._R;
                this.ve.y = 0;
                _loc_2.push(this.ve.x, this.ve.y, this.ve.z);
                if (this._radian != 2 * Math.PI && _loc_5 == this._segment)
                {
                    _loc_2.push(0, 0, 0);
                }
                _loc_5++;
            }
            param1.push(_loc_2);
            return;
        }// end function

        private function createQuaternion() : Quaternion
        {
            var _loc_1:* = new Quaternion();
            _loc_1.fromEulerAngles(this._rotateY, this._rotateZ, this._rotateX);
            return _loc_1;
        }// end function

    }
}
